home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / tclX-6.4 / help / files / dup < prev    next >
Encoding:
Text File  |  1992-12-17  |  1.5 KB  |  36 lines

  1.  
  2.  
  3.           dup filehandle [stdhandle]
  4.                Duplicate an open file.  A file handle is created that
  5.                addresses the same file as filehandle.
  6.  
  7.                A special case is allowed for duping files to stdin,
  8.                stdout or stderr.  If stdhandle is specified, then it
  9.                must contain either stdin, stdout, or stderr.  In this
  10.                form, the file corresponding to stdhandle is closed,
  11.                and the dup is performed from filehandle with the
  12.                result going to stdhandle.
  13.  
  14.                The procedure shown below will create a child process
  15.                and set its standard input and output filehandles to a
  16.                pair of pipe filehandles we pass as arguments.  Finally
  17.                the program does an execl of a specified command, with
  18.                the program's stdin and stdout coming from and going to
  19.                our pair of pipes.
  20.  
  21.                    proc ChildProcess {cmd inPipe outPipe} {
  22.                        if {[set childPid [fork]] == 0} {
  23.                            close stdin
  24.                            dup $inPipe stdin
  25.                            close $inPipe
  26.  
  27.                            close stdout
  28.                            dup $outPipe stdout
  29.                            close $outPipe
  30.  
  31.                            execl $cmd
  32.                            # will never make it here...
  33.                        }
  34.                        return $childPid
  35.                    }
  36.